﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using VM.Common.EntityEnum;
using VM.Common.Result;
using VM.IBLL;
using VM.IBLL.Files;
using VM.IDAL;
using VM.WebCore.Jwt;

namespace VM.BLL
{
    public abstract class BaseBLL : IBaseBLL
    {
        /// <summary>
        /// 优化传入的entity类，添加必要的赋值
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="x"></param>
        /// <param name="userId"></param>
        /// <param name="menuId"></param>
        /// <param name="enumvalue"></param>
        /// <returns></returns>
        public T perfectClass<T>(T x, int userId,  ProTypeEnum enumvalue) where T : class
        {


            Type type = typeof(T);
            PropertyInfo[] properties = type.GetProperties();
            if (enumvalue == ProTypeEnum.save)
            {

                foreach (PropertyInfo property in properties)
                {
                    if (property.Name == "createUserId" || property.Name == "updateUserId")
                    {
                        property.SetValue(x, userId);
                    }
                    if (property.Name == "createDate" || property.Name == "updateDate")
                    {
                        property.SetValue(x, DateTime.Now);
                    }
                    if (property.Name == "code")
                    {

                        property.SetValue(x, DateTime.Now);
                    }
                    if (property.Name == "billStatus")
                    {

                        property.SetValue(x, 1);
                    }
                }
            }
            else if (enumvalue == ProTypeEnum.update)
            {
                foreach (PropertyInfo property in properties)
                {
                    if (property.Name == "updateUserId")
                    {
                        property.SetValue(x, userId);
                    }
                    if (property.Name == "updateDate")
                    {
                        property.SetValue(x, DateTime.Now);
                    }
                }

            }

            return x;
        }



    
    }
}
